<template>
  <div>
    <h2>添加商品</h2>
    名称<input type="text" v-model="name">
    价格<input type="number" v-model="price">
    图片<input type="file" id="img">
    数量<input type="number" v-model="count">
    <button @click="sub">添加</button>
  </div>
</template>

<script>
export default {
  data(){
    return{
      name:'',
      price:0,
      count:0,
    }
  },
  methods:{
    sub:function(){
      let img=document.getElementById('img').files[0];

      let formdata=new FormData();
      formdata.append('name',this.name);
      formdata.append('price',this.price);
      formdata.append('count',this.count);
      formdata.append('img',img);

      this.axios({
        url:'http://127.0.0.1:8000/app01/goods/',
        method:'post',
        data:formdata,
      }).then(res=>{
        alert(res.data.msg)
      })
    }
  }
}
</script>

<style>

</style>
